package models

import (
	"fmt"

	"github.com/gin-gonic/gin"
)

type ApiRes struct {
	Code  int         `json:"code"`
	Msg   string      `json:"msg"`
	Data  interface{} `json:"data"`
	Error string      `json:"error"`
}

func WrapResponse(c *gin.Context, code int, message string, data interface{}, error string) {
	resp := ApiRes{
		Code:  code,
		Msg:   message,
		Data:  data,
		Error: error,
	}
	c.JSON(200, resp)
}

func ApiSuccess(c *gin.Context, data interface{}) {
	WrapResponse(c, 200, "success", data, "")
}

func ApiError(c *gin.Context, err error) {
	fmt.Println(err)
	WrapResponse(c, 300, "error", nil, err.Error())
}
